package com.zhengtoudai.ui.presenter;

import android.app.Activity;

import com.zhengtoudai.global.Config;
import com.zhengtoudai.http.HttpApi;
import com.zhengtoudai.http.HttpUtil;
import com.zhengtoudai.ui.bean.OnlyFinish;
import com.zhengtoudai.ui.bean.Result;
import com.zhengtoudai.ui.view.MyInvestView;
import com.zhengtoudai.util.AbToastUtil;

import javax.inject.Inject;

import rx.Observer;

/**
 * Created by Administrator on 2016/9/6 0006.
 */

public class OnlyFinishPresenterImpl extends BasePresenterImpl<MyInvestView<OnlyFinish>> implements OnlyFinishPresenter {
    private Activity mActivity;
    @Inject
    public OnlyFinishPresenterImpl(Activity mActivity) {
        this.mActivity=mActivity;
    }

    /**
     * @param numPerPage 每页多少条
     * @param pageNum    当前第几页
     */
    @Override
    public void getOnlyFinish(int numPerPage, int pageNum) {
        mSubscription = HttpApi.getInstance().getOnlyFinish(numPerPage + "", pageNum + "")
                .subscribe(new Observer<Result<OnlyFinish>>() {
                    @Override
                    public void onCompleted() {
                        mView.dismissDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        HttpUtil.disposeOnFailure(mActivity,e);
                        mView.dismissDialog();
                    }

                    @Override
                    public void onNext(Result<OnlyFinish> result) {
                        if (result.getCode()== Config.SUCCESSFUL_CODE) {
                            mView.onResult(result.getResult());
                        }else{
                            AbToastUtil.showToast(mActivity,result.getMessage());
                        }
                    }
                });
    }
}
